<?php
/*
 * 微信授权登录
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/11/2
 * Time: 16:17
 */
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Log;
class WeChatController extends  Controller{

    /*
    * 微信服务器端认证接口
    */
    public function serve(){
        Log::info('request arrived');
        $app = app('wechat.official_account');
        $app->server->push(function($message){
            return "欢迎关注 overtrue！";
        });
        return $app->server->serve();
    }

    /*
     * 微信授权获取用户的信息
     */
    public function user(){
        //由于使用了easyWechat中 中间件的方法进行授权，因此一句话搞定直接获取授权用户的信息如下：
        $wechat = session('wechat.oauth_user.default');
        echo "<pre>";
        print_r($wechat);
        echo "</pre>";
        exit();

    }

}